package test.unit.server;

import java.io.File;
import java.io.FileInputStream;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;


public class POIClient {

	public static void main(String args[]){
		
		String fileName = "";
		String serverUrl = "";
		if(args.length == 0){
			fileName = "D:/poidata/MPSR-MapPOISearch/08.xml";
			//fileName = "D:/poidata/APSR-AddressBasedSearch/00.xml";
		}else{
			fileName = args[0];
		}

		if(args.length < 2){
			//serverUrl = "http://211.115.75.233:9001";
			serverUrl = "http://127.0.0.1:9001";
		}else{
			serverUrl = args[1];
		}


		try{
			File f = new File(fileName);
			FileInputStream fs = new FileInputStream(f);
			
			byte b[] = new byte[(int)f.length()];
			fs.read(b);
			PostMethod post = new PostMethod(serverUrl);
			
			post.setRequestHeader("Content-type", "text/xml;charset=euc-kr");
			post.setRequestHeader("Content-Length", Integer.toString(b.length));
			post.setRequestBody(new String(b));

			HttpClient httpClient = new HttpClient();
			long begin = System.currentTimeMillis();
			int result = httpClient.executeMethod(post);
			long end = System.currentTimeMillis();
			System.out.println("Execute Time : " + (end - begin) + " microsec");
			System.out.println("Response Result : " + result);
			System.out.println("============================================================");
			System.out.println(post.getRequestBodyAsString());
			System.out.println("============================================================");
			System.out.print(post.getResponseBodyAsString());
			System.out.println("============================================================");

			post.releaseConnection();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
